package com.woniuxy.tms.accept.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.woniuxy.tms.accept.domain.dto.QuerryWaybillDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.woniuxy.tms.accept.domain.Waybill;
import com.woniuxy.tms.accept.service.IWaybillService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 货运单Controller
 *
 * @author dxw
 * @date 2022-04-20
 */
@RestController
@RequestMapping("/waybill")
public class WaybillController extends BaseController
{
    @Autowired
    private IWaybillService waybillService;

    /**
     * 查询货运单列表
     */
    @RequiresPermissions("accept:waybill:list")
    @GetMapping("/list")
    public TableDataInfo list(QuerryWaybillDTO waybill)
    {
        startPage();
        List<Waybill> list = waybillService.selectWaybillList(waybill);
        return getDataTable(list);
    }

    /**
     * 导出货运单列表
     */
    @RequiresPermissions("accept:waybill:export")
    @Log(title = "货运单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QuerryWaybillDTO waybill)
    {
        List<Waybill> list = waybillService.selectWaybillList(waybill);
        ExcelUtil<Waybill> util = new ExcelUtil<Waybill>(Waybill.class);
        util.exportExcel(response, list, "货运单数据");
    }

    /**
     * 获取货运单详细信息
     */
    @RequiresPermissions("accept:waybill:query")
    @GetMapping(value = "/{waybillId}")
    public AjaxResult getInfo(@PathVariable("waybillId") Long waybillId)
    {
        return AjaxResult.success(waybillService.selectWaybillByWaybillId(waybillId));
    }

    /**
     * 新增货运单
     */
    @RequiresPermissions("accept:waybill:add")
    @Log(title = "货运单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Waybill waybill)
    {
        return toAjax(waybillService.insertWaybill(waybill));
    }

    /**
     * 修改货运单
     */
    @RequiresPermissions("accept:waybill:edit")
    @Log(title = "货运单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Waybill waybill)
    {
        return toAjax(waybillService.updateWaybill(waybill));
    }

    /**
     * 删除货运单
     */
    @RequiresPermissions("accept:waybill:remove")
    @Log(title = "货运单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{waybillIds}")
    public AjaxResult remove(@PathVariable Long[] waybillIds)
    {
        return toAjax(waybillService.deleteWaybillByWaybillIds(waybillIds));
    }
}
